//
//  NSMutableAttributedStringExtension.swift
//  Common
//
//  Created by 我骑着蜗牛走天下 on 2025/3/25.
//

import Foundation
import UIKit

extension NSMutableAttributedString{
    
    /// 修改颜色
    public func addColors(color:UIColor,ranges: Array<NSRange>) {
        
        addKeys(key: .foregroundColor,value: color, ranges: ranges)
    }
    
    /// 基础修改
    public func addKeys(key:NSAttributedString.Key,value:Any,ranges: Array<NSRange>) {
        
        for range in ranges {
            addAttribute(key, value: value, range: range)
        }
    }
    
    /// 基础修改
    public func addKeys(key:NSAttributedString.Key,values:[Any],ranges: Array<NSRange>) {
        
        for index in 0...values.count {
            if index < values.count && index < ranges.count {
                addAttribute(key, value: values[index], range: ranges[index])
            }
        }
    }
    
}
